package cn.com.websocket.po;

import cn.com.websocket.enums.MessageEnum;
import cn.com.websocket.enums.YesOrNoEnum;
import cn.com.websocket.util.DateUtil;
import cn.com.websocket.util.GenSequenceUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class Message {

	/**
	 * <p>主键id</p>
	 * */
	private String id;
	/**
	 * <p>消息发送方</p>
	 * */
	private String source;
	/**
	 * <p>消息接收方</p>
	 * */
	private String target;
	/**
	 * <p>消息内容</p>
	 * */
	private String text;
	/**
	 * <p>消息类型(0:文本，1:附件，2:语音)</p>
	 * */
	private Integer msgType;

	/**
	 * <p>阅读标志(0:未阅，1:已阅)</p>
	 */
	private Integer read;

	/**
	 * <p>消息创建时间</p>
	 * */
	@JSONField(format="yyyy-MM-dd HH:mm:ss SSS")
	public Date createTime;
	/**
	 * <p>消息阅读时间</p>
	 * */
	@JSONField(format="yyyy-MM-dd HH:mm:ss SSS")
	public Date readTime;

	/**
	 * <p>策略标志(如果 是 history 与 ack ) 参考 MessageEnum.STRATEGY</p>
	 * */
	private String strategy;
	private String fileName;
	/**附件base64*/
	private String data;

	public Message(){super();}
	public Message(String source, String target, String text, MessageEnum.MSG_TYPE msgType){
		id= GenSequenceUtil.nextId();
		this.createTime= new Date();
		this.source=source;
		this.target=target;
		this.text=text;
		this.read= YesOrNoEnum.NO.getKey();
		this.msgType=msgType.getKey();
	}

	//public String toString(){return JSONObject.toJSONString(this); }
}
